<template>
	<view class="uni-content">
		<view class="login-logo">
			<image :src="logo"></image>
		</view>
		<!-- 顶部文字 -->
		<!-- 		<text class="title">请输入验证码</text>
		<text class="tip">短信验证码</text> -->
		<uni-forms :modelValue="formData">
			<uni-forms-item label="手机号" name="code">
				<input type="text" v-model="formData.phone" placeholder="请输入手机号" />
			</uni-forms-item> <uni-forms-item label="验证码" name="code">
				<input type="text" v-model="formData.code" placeholder="请输入短信验证码" />
			</uni-forms-item>
			<button class="uni-btn send-btn" type="primary" @click="handleLogin">登录</button>
			<button class="uni-btn send-btn" type="primary" @click="codeSend">发送验证码</button>
			<button class="uni-btn send-btn" type="primary" @click="handleBaiduAuth">百度授权登陆</button>
		</uni-forms>
	</view>
</template>

<script>
	import * as userService from "@/service/user.js"
	import {
		LOGIN_TYPE
	} from "@/constants.js"
	export default {
		data() {
			return {
				formData: {}
			}
		},
		methods: {
			async handleLogin() {
				const token = await userService.login({
					type: LOGIN_TYPE.PHONE,
					payload: this.formData
				})
				uni.setStorageSync("token", token);
				uni.redirectTo({
					url: '/pages/movie/index'
				})
			},
			async codeSend() {
				const token = await userService.codeSend({
					phone:this.formData.phone
				});
			},
			handleBaiduAuth(){
				window.location.href="http://localhost:8200/login/baidu"
			}
		},
	}
</script>

<style scoped lang="scss">
	@import "./login-page.scss";

	.tip {
		margin-top: -15px;
		margin-bottom: 15px;
	}

	.popup-captcha {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		padding: 20rpx;
		background-color: #FFF;
		border-radius: 2px;
		flex-direction: column;
		position: relative;
	}

	.popup-captcha .title {
		font-weight: normal;
		padding: 0;
		padding-bottom: 15px;
		color: #666;
	}

	.popup-captcha .close {
		position: absolute;
		bottom: -40px;
		margin-left: -13px;
		left: 50%;
	}

	.popup-captcha .uni-btn {
		margin: 0;
	}
</style>